package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingLevelPageParamDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "护理等级管理")
@Slf4j
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(NursingLevelPageParamDto nursingLevelPageParamDto){
        log.info("条件分页查询：{}",nursingLevelPageParamDto);
        PageResponse<NursingLevelVo> page = nursingLevelService.getPage(nursingLevelPageParamDto);
        return success(page);
    }

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有")
    public ResponseResult<List<NursingLevelVo>> getAll(){
        log.info("查询所有");
        List<NursingLevelVo> all = nursingLevelService.getAllLevel();
        return success(all);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto){
        log.info("新增等级{}",nursingLevelDto);
        nursingLevelService.addLevel(nursingLevelDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        log.info("查询护理等级，ID：{}",id);
        NursingLevelDto nursingLevelDto = nursingLevelService.getLevelById(id);
        return success(nursingLevelDto);
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        log.info("编辑的等级：{}",nursingLevelDto);
        nursingLevelService.updateLevelMsg(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult remove(@PathVariable Long id){
        log.info("删除护理等级：{}",id);
        nursingLevelService.removeLevel(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理等级")
    public ResponseResult changeStatus(@PathVariable Long id, @PathVariable Integer status){
        log.info("更新等级ID：{} 的状态为：{}",id,status);
        nursingLevelService.updateLevelStatus(id,status);
        return success();
    }




}
